import 'package:aio/aio.dart';
import 'package:app/src/config/app_data_config.dart';

/**
 * 获取签名（加密方式）
 * @param map 参数集合
 */
String getSign(Map map) {
  String token = AppDataConfig.getToken();//token
  String appSecret = AppDataConfig.getAppSecret();//密钥
  //print('密钥：$appSecret');
  String unSigned = appSecret+ "+";
  var listKeys = []; // List();
  map.keys.forEach((element) {
    listKeys.add(element);
  });
  listKeys.add('token');
  listKeys.sort(); //fixme 默认就是按照字符大小顺序排序。
  listKeys.forEach((key) {
    //print('key:\t$key');
    if ('token' == key) {
      unSigned += 'token' + token;
    } else {
      var value = map[key];
      unSigned += (key + (value == null ? "" : value.toString()));
    }
  });
  unSigned += ("+" + appSecret);

  ///dart: WSNBJHDR-1234-ZH88-6666-ZEKYFLEO1111000+data{"Equipment":"","barcode":"J20201009011001A","code":null,"factoryId":"1","processId":"09","versioncode":"225"}token758694741+WSNBJHDR-1234-ZH88-6666-ZEKYFLEO1111000
  ///java: WSNBJHDR-1234-ZH88-6666-ZEKYFLEO1111000+data{"Equipment":"","barcode":"J20201009011001A","code":null,"factoryId":"1","processId":"09","versioncode":"225"}token758694741+WSNBJHDR-1234-ZH88-6666-ZEKYFLEO1111000
  //print('$unSigned');
  String sign = toMd5With16(unSigned).toString().toLowerCase(); //md5加密签名
  return sign;
}
